package art_of_java_concurrent_programming.concurrent_util.count_down_latch;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch：B，C，D完成之后，开始执行 A 线程<br/>
 * 假设线程 A 等待线程 B，C，D 完成，那么伪代码如下：
 * CountDownLatch c = new CountDownLatch(3);
 * B，C，D --> c.countDown();
 * A --> c.await();
 * B，C，D 都执行 countDown() 后，A 线程开始执行
 */
public class CountDownLatchTest {
    static CountDownLatch c = new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
                c.countDown();
                System.out.println(2);
                c.countDown();
            }
        }).start();
        c.await();
        System.out.println("3");
    }
}